' Stephen Toub
' Coded and published in January 2007 issue of MSDN Magazine 
' http://msdn.microsoft.com/msdnmag/issues/07/01/PreviewHandlers/default.aspx


Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Microsoft.Ink
Imports C4F.DevKit.PreviewHandler.PreviewHandlerFramework

Namespace C4F.DevKit.PreviewHandler.PreviewHandlers
    <PreviewHandler("MSDN Magazine Serialized Ink Preview Handler", ".isf", "{10355E34-5C18-43dc-A257-8069A960AB89}"), ProgId("C4F.DevKit.PreviewHandler.PreviewHandlers.IsfPreviewHandler"), Guid("E90A8ADF-A1A7-42e8-87B9-02B3BFEE31F7"), ClassInterface(ClassInterfaceType.None), ComVisible(True)> _
    Public NotInheritable Class IsfPreviewHandler
        Inherits StreamBasedPreviewHandler
        Protected Overrides Function CreatePreviewHandlerControl() As PreviewHandlerControl
            Return New IsfPreviewHandlerControl()
        End Function

        Private NotInheritable Class IsfPreviewHandlerControl
            Inherits StreamBasedPreviewHandlerControl
            Public Overrides Sub Load(ByVal s As Stream)
                Dim p As Panel = New Panel()
                p.Dock = DockStyle.Fill

                Dim inkData As Byte() = New Byte(s.Length - 1) {}
                s.Read(inkData, 0, inkData.Length)

                Dim overlay As InkOverlay = New InkOverlay(p)
                overlay.Ink.Load(inkData)

                Controls.Add(p)
            End Sub
        End Class
    End Class
End Namespace